﻿#region using statements

using System;

using Microsoft.Xna.Framework;

using NGen;
using NGen.Managers.Collision;
using NGen.Managers.GUI;
using NGen.Managers.GameObject;

using Nuclex.UserInterface;
using Nuclex.UserInterface.Controls;

#endregion

namespace XNAGameDemo.GUI
{
	public class GUIElementPlay3State : GUIElement
	{
		private readonly LabelControl m_label = new LabelControl();

		private readonly WindowWithOkButtonControl m_window = new WindowWithOkButtonControl();

		protected override void _Initialize() {
			GameEngine.GetService<IManagerGameObjects>().SkipUpdate = true;
			GameEngine.GetService<IManagerCollision2D>().SkipUpdate = true;
			GameEngine.GetService<IManagerGUI>().SkipUpdate = true;
			m_window.Bounds = new UniRectangle(new UniScalar(0.5f, -250.0f), new UniScalar(0.25f, 0.0f), 500, 500);
			m_window.OkButton.Pressed += _OkButtonPressed;
			_Children.Add(m_window);

			m_label.Bounds = new UniRectangle(new UniScalar(0.075f, 0.0f), new UniScalar(0.2f, 0.0f), 0, 0);
			m_label.Text = "This state demonstrates how to use the collision " + "detection manager.\n\nWhen blocks collide with each other, " + "one block will transfer its color\nto the other.\n\n" + "When a block collides with the mouse controlled ball, its " + "color will be\n randomly changed and its position will be " + "reset\n\n The game will stop updating whenever the mouse is" + "hovering over\na GUI element";
			m_window.Children.Add(m_label);
		}

		protected override void Update(GameTime p_gameTime) {
			if(GameEngine.GetService<IManagerGUI>().MouseOverGUI()) {
				GameEngine.GetService<Game>().IsMouseVisible = true;
				GameEngine.GetService<IManagerGameObjects>().SkipUpdate = true;
			} else {
				GameEngine.GetService<Game>().IsMouseVisible = false;
				GameEngine.GetService<IManagerGameObjects>().SkipUpdate = false;
			}
		}

		protected override void _Cleanup() {}

		private void _OkButtonPressed(object p_sender, EventArgs p_e) {
			GameEngine.GetService<IManagerGameObjects>().SkipUpdate = false;
			GameEngine.GetService<IManagerCollision2D>().SkipUpdate = false;
			GameEngine.GetService<IManagerGUI>().SkipUpdate = false;
			_Children.Remove(m_window);

			Console.WriteLine("go");
		}
	}
}